package com.team.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.team.entity.FileSingle;
import com.team.util.DbHelp;
import com.team.util.ResultSetPackge;

public class FileDao {
	
	DbHelp<FileSingle> db = new DbHelp<FileSingle>();
	
	public List<FileSingle> selectAllByFolderId(int folderId){
		String sql = "select id ,name,filename,filesize,createtime,t_fileType_id,t_user_id from t_file where t_fileType_id = ? ";
		return db.exeSelectForList(sql, new PackgeFile(), folderId);
		
	}


	public int save(FileSingle fs) {
		String sql = "insert into t_file(name,filename,filesize,createtime,t_fileType_id,t_user_id)values(?,?,?,?,?,?)";
		return db.executeUpdateSql(sql, fs.getName(),fs.getFilenNme(),fs.getFileSize(),fs.getCreateTime(),fs.getFileTypeId(),fs.getUserId());
		
	}
	
	private class PackgeFile implements ResultSetPackge<FileSingle>{

		public FileSingle packgeResultSet(ResultSet rs) throws SQLException {
			FileSingle file = new FileSingle();
			file.setId(rs.getInt("id"));
			file.setName(rs.getString("name"));
			file.setCreateTime(rs.getString("createtime"));
			file.setFilenNme(rs.getString("filename"));
			file.setFileSize(rs.getFloat("filesize"));
			file.setFileTypeId(rs.getInt("t_fileType_id"));
			file.setUserId(rs.getInt("t_user_id"));
			return file;
		}
		
	}

}
	
	